<%@ Page Trace="false" Language="C#" %>
<%@ Register TagPrefix="Wrox" TagName="PageHeader" Src="/ch7/global/pageheader.ascx"%>
<%@ Register TagPrefix="Wrox" TagName="PageFooter" Src="/ch7/global/pagefooter.ascx"%>
<%@ Register TagPrefix="Wrox" Namespace="Wrox" Assembly="viewsource" %>


<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<Wrox:PageHeader runat=server />

<H2>Creating XML</H2>
<script runat=server>

	
	protected void RenderSimpleXML()
	{
		MemoryStream ms;
		ms = new MemoryStream();
		
		XmlTextWriter tw;
		
		tw = new XmlTextWriter( new StreamWriter(ms) );
		tw.Formatting = Formatting.Indented;
		tw.Indentation = 4;
		tw.WriteStartDocument();
		tw.WriteComment("A Simple XML File");
		tw.WriteStartElement("Books");
			tw.WriteStartElement("Book");
				tw.WriteAttribute("title","Professional ASP.NET");
			tw.WriteEndElement();
		tw.WriteEndElement();
		tw.WriteEndDocument();
		
		
		// Important to call to ensure text writer writes out to stream
		
		tw.Flush();
		
		// Reset stream position ready for reading
				
		ms.Seek( 0, SeekOrigin.Begin );

		TextReader tr = new StreamReader( ms );

		// Write out the XML inside of a PRE element to preserve XML formatting
		
		Response.Write("<pre>");		
		Response.Write( HttpUtility.HtmlEncode( tr.ReadToEnd() ) );
		Response.Write("</pre>");		

	}

</script>

<%
	RenderSimpleXML();
%>

<Wrox:PageFooter runat=server />
